<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>${sessionScope.title}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../admin/css/x-admin.css" media="all">
    <link rel="stylesheet" href="/layui-v2.2.5/layui/css/layui.css" media="all">
</head>
<body>
<div class="x-nav" >
            <span class="layui-breadcrumb" >
              <a><cite>首页</cite></a>
              <a><cite>会员管理</cite></a>
              <a><cite>管理员列表</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <form class="layui-form x-center" action="/adminSystem/adminList" style="width:80%">
        <div class="layui-form-pane" style="margin-top: 15px;">
            <div class="layui-form-item">
  <%--              <label class="layui-form-label">日期范围</label>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="开始日" id="LAY_demorange_s" >
                </div>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="截止日" id="LAY_demorange_e" >
                </div>--%>
                <input type="hidden" name="type" value="1">
                <input type="hidden" name="size" value="10">
                <input type="hidden" name="currentPage" value="1">
                <div class="layui-input-inline">
                    <input type="text" name="userCode"  value="${userCode}" placeholder="请输入登录名" autocomplete="off" class="layui-input">
                </div>
               <div class="layui-input-inline">
                      <input type="text" name="userName" value="${userName}"   placeholder="请输入管理员名称" autocomplete="off" class="layui-input">
               </div>
                <div class="layui-input-inline" style="width:80px">
                    <button class="layui-btn"  lay-submit="" lay-filter="/adminSystem/adminList"><i class="layui-icon">&#xe615;</i></button>
                </div>
            </div>
        </div>
    </form>
    <xblock><button class="layui-btn" onclick="admin_add('添加用户','/adminSystem/goAdminEdit?id=&type=${type}','600','500')"><i class="layui-icon">&#xe608;</i>添加</button></xblock>
        <table class="layui-table" >
                <thead>
                <tr>
                   <%-- <th>
                        ID
                    </th>--%>
                    <th>
                        登录账号
                    </th>
                    <th>
                        名称
                    </th>
                    <th>
                        角色
                    </th>
                       <%--<th>
                           盐
                       </th>--%>
                    <th>
                        状态
                    </th>
                    <th>
                        管理权限
                    </th>
                    <th>
                        操作
                    </th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${list}" var="lli">
                    <tr>
                        <td>
                            ${lli.userCode}
                        </td>
                        <td >
                                ${lli.userName}
                        </td>
                        <td >
                            <a title="编辑" href="javascript:;" onclick="admin_edit('设置角色','/adminSystem/goEditUserRole?id=${lli.id}&type=${type}','','510')"
                               class="layui-btn" style="text-decoration:none">
                                设置角色
                            </a>
                        </td>
                                <%--<td >
                                    ${lli.salt}
                                </td>--%>

                        <td class="td-status">

                            <c:if test="${lli.locked ==0}"><span class="layui-btn layui-btn-normal layui-btn-mini">
                                已启用</span>
                            </c:if>
                            <c:if test="${lli.locked ==1}"><span class="layui-btn layui-btn-normal layui-btn-mini">
                                            已启用</span>
                            </c:if>

                        </td>
                        <td>
                            <button class="layui-btn layui-btn-radius "  onclick="admin_edit('一级菜单','/adminSystem/onePermission?type=user&id=${lli.id}','1400','750')">管理菜单权限
                            </button>
                        </td>
                        <td class="td-manage">
                            <c:if test="${sessionScope.userType==0}">
                                <button class="layui-btn layui-btn-radius "  onclick="orgNumber_edit('${lli.id}')">
                                    机构数量${lli.orgNumber}
                                </button>
                            </c:if>
                            <a title="编辑" href="javascript:;" onclick="admin_edit('编辑','/adminSystem/goAdminEdit?id=${lli.id}&type=${type}','','510')"
                               class="layui-btn" style="text-decoration:none">
                                编辑
                            </a>
                            <a title="删除" href="javascript:;" onclick="admin_del(this,'${lli.id}')"
                               style="text-decoration:none" class="layui-btn layui-btn-danger">
                                删除
                            </a>

                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
</div>
<script src="../../admin/js/jquery.min.js" type="text/javascript" language="javascript"></script>
<script src="/layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
<script src="../../admin/js/x-layui.js" charset="utf-8"></script>
<script>

</script>
<script>
    layui.use(['laydate','element','form','laypage','layer'], function() {
        var element = layui.element;
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        lement = layui.element;//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        form = layui.form;


        //批量删除提交
        function delAll() {
            layer.confirm('确认要删除吗？', function (index) {
                //捉到所有被选中的，发异步进行删除
                layer.msg('删除成功', {icon: 1});
            });
        }





        /*启用*/
        function admin_start(obj, id) {
            layer.confirm('确认要启用吗？', function (index) {
                //发异步把用户状态进行更改
                $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="admin_stop(this,id)" href="javascript:;" title="停用"><i class="layui-icon">&#xe601;</i></a>');
                $(obj).parents("tr").find(".td-status").html('<span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span>');
                $(obj).remove();
                layer.msg('已启用!', {icon: 6, time: 1000});
            });
        }




    });

    /*删除*/
    function admin_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            $.ajax({
                url: '/adminSystem/delAdmin',
                type: 'POST', //GET
                async: true,    //或false,是否异步
                data: {
                    id: id
                },
                timeout: 5000,    //超时时间
                dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend: function (xhr) {
                    /*console.log(xhr)
                 console.log('发送前')*/
                },
                success: function(data){
                    if
                    (
                        true== data){
                        $(
                            obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time: 1000});
                    }
                    else {
                        layer.msg('删除失败!',{icon:5,time:1000});
                    }
                }, error:function(xhr, textStatus){
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                }, complete: function() {
                    //console.log('结束')
                }
            })

        });
    }



    /*添加*/
    function admin_add(title, url, w, h) {
        layer.open({
            title:title,
            type: 2,
            content: url,
            area: ["50%", "70%"],
            shadeClose:true,
            end:function () {
                window.location.reload();
            }
        });
    }
    //编辑
    function admin_edit(title, url, w, h) {
        layer.open({
            title:title,
            type: 2,
            content: url,
            offset: '20px',
            shade:[0.8, '#393D49'],
            shadeClose:true,
            area: ["90%", "90%"]
        });
    }




</script>



<script type="application/javascript">
    /*分页*/
    layui.use(['laypage', 'layer'], function(){
        var laypage = layui.laypage
            ,layer = layui.layer;
        //自定义排版
        laypage.render({
            elem: 'fenye'
            ,limit:"${size}"
            ,count: parseInt(${totalRows})
            ,layout: ['limit', 'prev', 'page', 'next']
            ,curr: ${currentPage} //获取起始页
            ,hash: 'fenye' //自定义hash值
            ,jump: function(obj,first){
                var curr=obj.curr;//当前页
                var limit=obj.limit;//每页显示的条数
                //首次不执行
                if(!first){
                    //写自己的逻辑
                    window.location.href="/adminSystem/adminList?currentPage="
                        +curr+"&size="+limit+"&type="+${type};
                }else {

                }
            }
        });
    });
    /**
     * 编辑机构数量
     */
    function orgNumber_edit(id) {
        layer.open({
            type: 2,
            title:"机构信息",
            shadeClose:true,
            area: ['65%', '65%'],
            content: '/adminSystem/goOrgNumberEdit?id='+id,
            end:function () {
                window.location.reload();
            }
        });
    }




</script>

<div id="fenye" style="text-align: center;margin-top: -2rem" ></div>

</body>
</html>